"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getObj = exports.transParams = exports.getMapper = void 0;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const cache_1 = require("./cache");
function transParams(params, paramsData) {
    let newParams = [];
    for (let i = 0; i < params.length; i++) {
        const ps = params[i];
        const val = paramsData[ps];
        if (val != undefined) {
            newParams.push(val);
        }
        else {
            newParams.push('');
        }
    }
    return newParams;
}
exports.transParams = transParams;
function getMapper(mapperName, sqlName) {
    let sql = "";
    let params = [];
    const sqlCache = cache_1.getCache(mapperName, sqlName);
    if (sqlCache == null) {
        const configPath = "sqlconfig.json";
        const config = JSON.parse(fs_1.default.readFileSync(configPath).toString());
        const mapperPath = path_1.default.join(config.mapperPath, `${mapperName}.json`);
        const mapper = JSON.parse(fs_1.default.readFileSync(mapperPath).toString());
        sql = mapper[sqlName].sql;
        params = mapper[sqlName].params;
        cache_1.setCache(mapperName, sqlName, sql, params);
    }
    else {
        sql = sqlCache.sql;
        params = sqlCache.params;
    }
    return { sql, params };
}
exports.getMapper = getMapper;
function getObj(data) {
    let dataString = JSON.stringify(data);
    let obj = JSON.parse(dataString);
    return obj;
}
exports.getObj = getObj;
